package com.woniuxy.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	private volatile static SessionFactory sessionFactory = null;
	
	public static SessionFactory getSessionFactory(){
		synchronized (HibernateUtil.class) {
			if(sessionFactory == null){
				synchronized (HibernateUtil.class) {
					Configuration configuration = new Configuration().configure();
					sessionFactory = configuration.buildSessionFactory();
				}
			}
		}
		return sessionFactory;
	}
	
	public static void close(SessionFactory sessionFactory,Session session){
		session.close();
		sessionFactory.close();
	}
}
